﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Com.DA;
using Com.BU;
using Com.GUI.LibraryManager.Controls.SubControl;

namespace Com
{
    /// <summary>
    /// Interaction logic for ucAirSpace.xaml
    /// </summary>
    public partial class ucAirSpace : UserControl
    {
        ucAirConditionPlace uc0 = new ucAirConditionPlace();
        ucHeatEmiteByPeople uc1 =  new ucHeatEmiteByPeople();
        ucExitingAire uc2 = new ucExitingAire();
        public ucAirSpace()
        {
            this.InitializeComponent();
            cbxDescription.SelectedIndex = 0;
            enableButtons();
        }

       

        private void enableButtons()
        {
            btnCancel.IsEnabled = false;
            btnSave.IsEnabled = false;

            btnNew.IsEnabled = true;
            btnCopy.IsEnabled = true;
            btnDelete.IsEnabled = true;
        }

        private void disableButtons()
        {
            btnCancel.IsEnabled = true;
            btnSave.IsEnabled = true;

            btnNew.IsEnabled = false;
            btnCopy.IsEnabled = false;
            btnDelete.IsEnabled = false;
        }

        private void cbxDescription_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            dockPanel1.Children.Clear();
            if (cbxDescription.SelectedIndex == 0)
            {
                dockPanel1.Children.Add(uc0);
            }

            if (cbxDescription.SelectedIndex == 1)
            {
                dockPanel1.Children.Add(uc1);
            }

            if (cbxDescription.SelectedIndex == 2)
            {
                dockPanel1.Children.Add(uc2);
            }
        }

        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            if (cbxDescription.SelectedIndex == 0)
            {
                uc0.saveData();
                enableButtons();
            }

            if (cbxDescription.SelectedIndex == 1)
            {
                dockPanel1.Children.Add(uc1);
            }

            if (cbxDescription.SelectedIndex == 2)
            {
                dockPanel1.Children.Add(uc2);
            }
        }

        private void btnCancel_Click(object sender, RoutedEventArgs e)
        {
            if (cbxDescription.SelectedIndex == 0)
            {
                uc0.reloadData();
                enableButtons();
            }

            if (cbxDescription.SelectedIndex == 1)
            {
                dockPanel1.Children.Add(uc1);
            }

            if (cbxDescription.SelectedIndex == 2)
            {
                dockPanel1.Children.Add(uc2);
            }
        }

        private void btnNew_Click(object sender, RoutedEventArgs e)
        {
            if (cbxDescription.SelectedIndex == 0)
            {
                uc0.addNew();
                disableButtons();
            }

            if (cbxDescription.SelectedIndex == 1)
            {
                dockPanel1.Children.Add(uc1);
            }

            if (cbxDescription.SelectedIndex == 2)
            {
                dockPanel1.Children.Add(uc2);
            }
        }

        private void btnCopy_Click(object sender, RoutedEventArgs e)
        {
            if (cbxDescription.SelectedIndex == 0)
            {
                uc0.copyData();
                disableButtons();
            }

            if (cbxDescription.SelectedIndex == 1)
            {
                dockPanel1.Children.Add(uc1);
            }

            if (cbxDescription.SelectedIndex == 2)
            {
                dockPanel1.Children.Add(uc2);
            }
        }

        private void btnDelete_Click(object sender, RoutedEventArgs e)
        {
            if (cbxDescription.SelectedIndex == 0)
            {
                uc0.delData();
            }

            if (cbxDescription.SelectedIndex == 1)
            {
                dockPanel1.Children.Add(uc1);
            }

            if (cbxDescription.SelectedIndex == 2)
            {
                dockPanel1.Children.Add(uc2);
            }
        }

        private void LayoutRoot_Loaded(object sender, RoutedEventArgs e)
        {
            //uc0 = new ucAirConditionPlace();
            //uc1 = new ucHeatEmiteByPeople();
            //uc2 = new ucExitingAire();
        }

    }


}